import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Demo {
    public static void main(String[] args) {
//        String[] first = {"abc", "ab"};
//        String[] second = {"a", "abcd"};
//        Demo demo = new Demo();
//        String[] result = demo.mergeArray(first, second);
//        for (String s : result) {
//            System.out.print(s + ",");
//        }

        int[] numbers = {1,3,5};
        Demo demo = new Demo();
        System.out.println(demo.countOne(numbers));
    }

    public String[] mergeArray (String[] first, String[] second) {
        // write code here
        int a = first.length;
        int b = second.length;
        List<String> merge = new ArrayList<>();

        for(int i = 0;i < a; i++) {
            merge.add(first[i]);
        }

        for(int i = 0;i < b; i++) {
            merge.add(second[i]);
        }

        Collections.sort(merge, new Comparator(){
            @Override
            public int compare(Object o1, Object o2) {
                String s1 = (String)o1;
                String s2 = (String)o2;
                return s1.length() - s2.length();
            }
        });

        String[] result = new String[a+b];
        int index = 0;

        for(String each : merge) {
            result[index++] = each;
        }

        return result;
    }

    public int countOne (int[] numbers) {
        // write code here
        int cost = 0;
        for(int i = 0;i < numbers.length;i++) {
            int count = 0;
            int number = numbers[i];
            while (number != 1) {
                count++;
                number = change(number);
            };
            cost += count;
        }
        return cost;
    }

    public int change(int x) {
        int count = 0;
        while (x != 0) {
            count += x & 1;
            x >>>= 1;
        }
        return count;
    }
}
